package com.zxjbyte.yiyi.module.system.api.oss;

import com.zxjbyte.yiyi.module.system.domain.dto.oss.OssFileAddDTO;
import com.zxjbyte.yiyi.module.system.domain.entity.OssFilePO;
import com.zxjbyte.yiyi.module.system.domain.model.oss.OssFileModel;
import com.zxjbyte.yiyi.module.system.service.oss.IOssFileService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Optional;

/**
 * @Author zhangxingjia
 * @Date 2023/6/20 14:35
 * @Version: 1.0
 */
@Service
public class OssFileApiImpl implements OssFileApi{

    @Resource
    private IOssFileService ossFileService;

    @Override
    public void addFile(OssFileAddDTO addDto) {
        ossFileService.add(addDto);
    }

    @Override
    public OssFileModel getContent(String path) {
        OssFilePO entity = ossFileService.getByPath(path);
        return Optional.ofNullable(entity).map(s->{
            OssFileModel model = new OssFileModel();
            model.setContent(s.getContent());
            model.setCreateTime(s.getCreateTime());
            return model;
        }).orElse(null);
    }

    @Override
    public boolean deleteByPath(String path) {
        return ossFileService.deleteByPath(path);
    }
}
